package cn.stylefeng.guns.modular.controller;


import cn.stylefeng.guns.sys.core.util.UeditorUtil;
import cn.stylefeng.guns.sys.modular.system.model.UeditorFileResult;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;

@RestController
@RequestMapping("/ueditor")
public class UeditorController extends BaseController {


    /**
     * 配置文件
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/config")
    @ResponseBody
    public Object ueditorConfig() throws Exception {
        ClassPathResource classPathResource = new ClassPathResource("assets/common/UEditor/jsp/config.json");
        byte[] bytes = FileUtil.toByteArray(classPathResource.getFile().getPath());
        return JSONObject.parse(new String(bytes));
    }


    /**
     *
     * @param upfile
     * @return
     */
    @RequestMapping(value = "/imgUpload")
    @ResponseBody
    public UeditorFileResult imgUpload(MultipartFile upfile) {
        return UeditorUtil.uploadFile(upfile, UeditorUtil.FileType.IMG);
    }

}



